package server;

import java.util.LinkedList;
import java.util.Queue;

import communication.Request;

/**
 * <h1>Class RequestBuffer</h1>
 * 
 * The class RequestBuffer represents a queue with all the requests made
 * by the clients which haven't been served yet.
 * 
 * @author Tomas
 * @date March 4 2009
 */
public class RequestBuffer {

	/**
	 * Buffer for the request. To be implemented as a FIFO LinkedList.
	 */
	protected Queue<Request> buffer = null;
	
	/**
	 * Default constructor. Initializes a RequestBuffer.
	 */
	public RequestBuffer(){
		
		buffer = new LinkedList<Request>();
		
	}
	
	/**
	 * Stores a request in the buffer.
	 * 
	 * @param r
	 * 		Request to be stored.
	 */
	public void storeRequest(Request r){
		
		buffer.add(r);
		
	}
	
	/**
	 * Obtains a request from the buffer.
	 * 
	 * @return
	 * 		Request object, if there is any in the buffer; null otherwise.
	 */
	public Request getRequest(){
		
		return buffer.poll();
		
	}
	
}
